<div class="page-header">
  <h3>修改用户信息</h3>
</div>
<%= form_tag admins_account_path(@user), method: :put, class: "form-horizontal edit_user_info" do %>
  <div class="form-group">
    <label for="" class="col-sm-2 control-label">用户名</label>
    <div class="col-sm-10">
      <input type='text' name='user[login]' value="<%=@user.login %>" />
    </div>
  </div>
  <div class="form-group">
    <label for="" class="col-sm-2 control-label">姓名</label>
    <div class="col-sm-10">
      <input type='text' name='user[name]' value="<%=@user.name %>" />
    </div>
  </div>
  <div class="form-group">
    <label for="" class="col-sm-2 control-label">邮箱</label>
    <div class="col-sm-10">
      <input type='text' name='user[email]' value="<%=@user.email %>" />
    </div>
  </div>

  <div class="form-group">
    <label for="" class="col-sm-2 control-label">部门</label>
    <div class="col-sm-10">
      <select name='user[department_id]'>
        <% Department.all.each do |dep| %>
        <option value="<%=dep.id %>" <%= "selected" if dep==@user.department %>><%=dep.name %></option>
        <% end %>
      </select>
    </div>
  </div>

  <div class="form-group">
    <label for="" class="col-sm-2 control-label">办公电话</label>
    <div class="col-sm-10">
      <input type='text' name='user[office_phone]' value="<%=@user.office_phone %>" />
    </div>
  </div>

  <div class="form-group">
    <label for="" class="col-sm-2 control-label">手机号码</label>
    <div class="col-sm-10">      
      <input type='text' name='user[mobile]' value="<%=@user.mobile %>" />
    </div>
  </div>

  <% if current_user.admin? %>
      <div class="form-group">
        <label for="" class="col-sm-2 control-label">角色</label>
        <div class="col-sm-10">
          <% Group.all.each do |group| %>
            <input type='checkbox' value="<%=group.id %>" class='group_name' name='user[group][]' <%="checked" if @user.groups.include?(group) %>  /><%=group.name %>
          <% end %>
        </div>
      </div>
  <% end %>

  <div class="form-group">
    <label for="" class="col-sm-2 control-label">上次登录时间</label>
    <div class="col-sm-10">
      <%= @user.last_sign_in_at.strftime("%Y-%m-%d %H:%M:%S").to_s if @user.last_sign_in_at %>
    </div>
  </div>

  <div class="form-group">
    <label for="" class="col-sm-2 control-label">上次登录ip</label>
    <div class="col-sm-10">
      <%= @user.last_sign_in_ip %>
    </div>
  </div>

  <div class="form-group">
    <div class="col-sm-offset-2 col-sm-10">
      <button type="submit" class="btn btn-default btn-primary">更新</button>
      <button type='button' class="btn btn-default btn btn-info" data-toggle="modal" data-target="#user_edit_password">修改密码</button>
    </div>
  </div>
<% end %>


<div class="modal fade user_edit_password" id="user_edit_password">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">
          <span aria-hidden="true">&times;</span><span class="sr-only">Close</span>
        </button>
        <h4 class="modal-title">修改密码</h4>
      </div>
      <div class="modal-body">
        <form  action="<%=update_password_admins_account_path %>">
          <div class="alert alert-warning notify" role="alert"></div>
          <div class="alert alert-success notify" role="alert"></div>
          <div class="form-group">
            <label>新密码</label>
            <input type="password" name="user[password]" class="form-control name password" placeholder="">
          </div>
          <div class="form-group">
            <label>确认密码</label>
            <input type="password" name="user[password_confirmation]" class="form-control name password_confirmation" placeholder="">
          </div>
        </form>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default cancel" data-dismiss="modal">关闭</button>
        <button type="button" class="btn btn-primary save" >保存</button>
      </div>
    </div>
  </div>
</div>